/**
	

	@author Matthew Richmond
	@version 2005-08-18
*/
class timber.math.Random {
	
	
	/**
	Return a random number between a range of numbers
	@param min:		Minimum value
	@param max:		Maximum value
	@param decPl:	(optional) the amount of decimal places in returned number
	@param last:	(optional) If set, excludes this number from possible return values.
	
	@returns Number.
	
	@usage
	<code>
	var randFrame = Random.range(2, this.totalFrames);
	var randFrame = Random.range(2, this.totalFrames, 0);
	var randFrame = Random.range(2, this.totalFrames, 0, this._parent.currentFrame);
	</code>
	*/
	
	static function range(min:Number, max:Number, decPl:Number, last:Number):Number{
		// no need to always specify the decPl;
		if (!decPl) var decPl:Number = 0;
		
		// Find the difference in the range and add one (we'll call this the delta).
		var rangeDiff = (max - min) * Math.pow(10, decPl) + 1;
		
		if (last == undefined) {
			// Multiply the delta by the result of Math.random() to generate a value between
			// 0 and 0.999 * delta.
			var randVal = Math.random() * rangeDiff;
			// Round the value to the desired number of decimal places.
			randVal = Math.floor(randVal);
			randVal /= Math.pow(10, decPl);
			// Add the random offset to min to generate a random number in the correct range.
			randVal += min;
			// Return the random value.
			return randVal;
			
		} else {
			
			do {
				// Multiply the delta by the result of Math.random() to generate a value between
				// 0 and 0.999 * delta.
				var randVal = Math.random() * rangeDiff;
				// Round the value to the desired number of decimal places.
				randVal = Math.floor(randVal);
				randVal /= Math.pow(10, decPl);
				// Add the random offset to min to generate a random number in the correct range.
				randVal += min;
				// Return the random value.
				var num:Number = randVal;
			} while (num == last);	
				return num;
			
		};
	};

};
